#pragma once

#include "D3DGlobal.h"
#include "Player.h"
#include "Menu.h"

enum unitType {EMPTY, PLAYER, ENEMY, STAR, MISSILE, STATION} ;

#define MAX_TEXTURES 6
//#define MAX_SECTORS 64

class DXGraphics 
{
private:
	//////////////////////////////////////////////////////////////////////////
	// DirectX Variables
	//////////////////////////////////////////////////////////////////////////
	HWND				m_hWnd;			//Handle

	bool				m_bVsync;		//Vertical sync

	bool				m_mouseClicked ; //single click check

	IDirect3D9*			m_pD3DObject;	//Direct3D object

	//IDirect3DDevice9*	m_pD3DDevice;	//Direct3D device

	D3DCAPS9			m_D3DCaps;		//Direct3D capabilities

	ID3DXFont*			m_pD3DFont;		//Font

	ID3DXSprite*		m_pD3DSprite;	//Sprite

	LPDIRECTINPUT8		m_pDirectInput; //Direct Input device

	LPDIRECTINPUTDEVICE8 m_pInKeyboard; //Keyboard device
	
	LPDIRECTINPUTDEVICE8 m_pInMouse;	//Mouse device

	DIMOUSESTATE		m_pMouseState;	//Mouse information storage

	IDirect3DTexture9*	m_pTexture[MAX_TEXTURES];	//Textures

	D3DXIMAGE_INFO		m_imageInfo;	//Texture info


	//////////////////////////////////////////////////////////////////////////
	// FMOD Variables
	//////////////////////////////////////////////////////////////////////////
	/*FMOD_RESULT result;

	FMOD::System *system;

	FMOD::Sound* sound;

	FMOD::Channel* channel[2];

	FMOD::Sound* stream;*/


	//////////////////////////////////////////////////////////////////////////
	// Game-related variables
	//////////////////////////////////////////////////////////////////////////

	float m_pDt,		//Delta time
		timeElapsed;				

	bool once;

	//struct vec2
	//{
	//	vec2(){x = 0.0f; y = 0.0f;}; //Default constructor
	//	vec2(float a, float b){x = a; y = b;}; //Parameterized

	//	float x, y;

	//};

	//vec2 selection,
	//	current_position,
	//	last_position,
	//	delta_position,
	//	cursor_position,
	int	sector_area[64];
	int					unit;
	int					unitPos;

	POINT pt;

	// matrix declarations
	D3DXMATRIX spriteScaling ;
	D3DXMATRIX spriteRotation ;
	D3DXMATRIX spriteTranslation ;
	D3DXMATRIX matTransform ;
	POINT mousePos ; //holds the position of the mouse within the game client window

	// vector declarations
	D3DXVECTOR3 center ;
	D3DXVECTOR3 position ;

	Player *m_player;			//pointer to player class

	Menu *m_menu;

	//////////////////////////////////////////////////////////////////////////
	// WinSock Variables
	//////////////////////////////////////////////////////////////////////////
	WSADATA wsaData;
	SOCKET 	Socket;

	int retval;			//Return value for recv function
	char bufferIn[1];	//Buffer for character received
	char bufferIn2[5];	//Buffer for character received
	char bufferOut[1];	//Buffer for character sent

public:
	DXGraphics( ) ;
	~DXGraphics( ) ;
	// function prototypes
	IDirect3DDevice9* GetDevice( ) { return m_pD3DDevice; }	//Direct3D device
	void initD3D(HWND hWnd) ;    // sets up and initializes Direct3D
	void Update( float dt ) ;
	void render_frame( ) ;    // renders a single frame
	void cleanD3D(void) ;    // closes Direct3D and releases memory

	void RunClient();
} ;

extern DXGraphics* gDX ;